const { string } = require('joi');
const mongoose = require('mongoose');
const { User } = require('./user');
const articleSchema = new mongoose.Schema({
    title: {
        type: String,
        // 数组的第二个参数为错误信息
        required: [true, '请填写文章标题'],
        minlength: 4,
        maxlength: 20
    },
    author: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        required: [true, '请写入作者名称'],
    },
    publishDate: {
        type: Date,
        default: Date.now,
    },
    cover: {
        type: String,
        default: null
    },
    content: {
        type: String
    }
});

const Article = mongoose.model('Article', articleSchema);

module.exports = {
    Article
}

